package ksv.cron.bean;

import api.common.util.TextUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * @创建人 xiaojiancheng
 * @时间 2020/8/15
 * @描述 调用记录
 */
@Setter
@Getter
public class SysCronLog {
    @TableId
    private Long id;
    private Long cronId;
    private Long userId;

    private LocalDateTime createTime = LocalDateTime.now();
    private String logKey;

    @JSONField(serialize = false)
    private String result;
    private String status;

    @TableField(exist = false)
    private Map<String,Object> resultMap;

    public void setResult(String result) {
        this.result = result;
        if(!TextUtils.isEmpty(result)){
            resultMap = JSON.parseObject(result);
        }
    }

    public void setResultMap(Map<String, Object> resultMap) {
        this.resultMap = resultMap;
        if(resultMap != null){
            result = JSON.toJSONString(resultMap);
        }
    }
}
